﻿using Dapper;
using HBase;
using hCommand;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Persistence.other
{
    internal class XydServer : AbsBaseServer, IBaseServer
    {

        private static IDbConnection conn;
        protected override IDbConnection opConn()
        {
            if (conn == null)
            {
                conn = DBUtils.createConnection(getGKDBType(), "DB_XYD");
            }
            return conn;

        }

        protected override GKDBType getGKDBType()
        {
            return GKDBType.sqlserver;
        }

        public CoreStock getDcxrk(String qzid)
        {
            string sql = @"SELECT dcxrk01 inTime  ,dcxrk02  ,dcxrk03 rk  ,dcxrk04 oi ,dcxrk05 no
                                 ,dcxrk06 ,dcxrk07   ,dcxrk08 cz  ,dcxrk09 th,dcxrk10 wd
                                 ,dcxrk11 ,dcxrk12  ,dcxrk13  ,dcxrk14 zz   ,dcxrk15 mz
                                 ,dcxrk16 sz ,dcxrk17 cd ,dcxrk18
                         FROM  dcxrk  where dcxrk29=@qzid ";
            CoreStock cs = opConn().QueryUnique<CoreStock>(sql, new { qzid });

            return cs;
        }
        public CoreStock getLxrk(String lxrk06)
        {
            string sql = @"SELECT  lxrk01    ,lxrk02 rk  ,lxrk03 inTime  ,lxrk04 oi ,lxrk05 no
                                   ,lxrk06   ,lxrk07 cz,lxrk08  th       ,lxrk09 wd ,lxrk10 zz
                                   ,lxrk11 mz,lxrk12 sz,lxrk13 cd 
              FROM  lxrk  where lxrk06=@lxrk06 and lxrk15 is null ORDER BY inTime DESC";
            CoreStock cs = opConn().Query<CoreStock>(sql, new { lxrk06 }).ToList().FirstOrDefault();
            if (cs != null)
            {
                cs.boxCode = lxrk06;

            }
            return cs;
        }
        public CoreStock getDcxrkSelect(String qzid)
        {
            string sql = @"SELECT dcxrk01 inTime  ,dcxrk02  ,dcxrk03 rk  ,dcxrk04 oi ,dcxrk05 no
                                 ,dcxrk06 ,dcxrk07   ,dcxrk08 cz  ,dcxrk09 th,dcxrk10 wd
                                 ,dcxrk11 ,dcxrk12  ,dcxrk13  ,dcxrk14 zz   ,dcxrk15 mz
                                 ,dcxrk16 sz ,dcxrk17 cd ,dcxrk18
                         FROM  dcxrk  where dcxrk29=@qzid";
            CoreStock cs = opConn().QueryUnique<CoreStock>(sql, new { qzid });

            return cs;
        }
        public CoreStock getLxrkSelect(String lxrk06)
        {
            string sql = @"SELECT  lxrk01    ,lxrk02 rk  ,lxrk03 inTime  ,lxrk04 oi ,lxrk05 no
                                   ,lxrk06   ,lxrk07 cz,lxrk08  th       ,lxrk09 wd ,lxrk10 zz
                                   ,lxrk11 mz,lxrk12 sz,lxrk13 cd 
              FROM  lxrk  where lxrk06=@lxrk06 and lxrk15 is null ORDER BY inTime DESC";
            CoreStock cs = opConn().Query<CoreStock>(sql, new { lxrk06 }).ToList().FirstOrDefault();
            if (cs != null)
            {
                cs.boxCode = lxrk06;

            }
            return cs;
        }
        public void syncedLxrk(String lxrk06)
        {
            String sql = "update lxrk set lxrk15=1,lxrk16=getDate()  where lxrk06 = @lxrk06 and  lxrk15 is null ";
            opConn().Execute(sql, new { lxrk06 });
        }

        public void syncedDcxrk(String code)
        {
            String sql = "update Dcxrk set dcxrk27=1,dcxrk28=getDate()  where dcxrk29 = @code";
            opConn().Execute(sql, new { code });
        }

        protected override IDbConnection readConn() {
            throw new NotImplementedException();
        }
    }
}
